package cn.zswltech.gruul.biz.comparator;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Comparator;

/**
 * @create: 2022-07-18
 **/

public class JsonObjectComparator implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        JSONObject J1 = (JSONObject) o1;
        JSONObject J2 = (JSONObject) o2;
        if (J1.getInteger("sortNo") == null) {
            return -1;
        } else if (J2.getInteger("sortNo") == null) {
            return 1;
        } else {
            int result = J1.getInteger("sortNo").compareTo(J2.getInteger("sortNo"));
            if (result == 0) {
                return J1.getDate("gmtCreate").compareTo(J2.getDate("gmtCreate"));
            } else {
                return result;
            }
        }
    }
}
